import java.util.concurrent.CountDownLatch;
import java.util.logging.Logger;


public class TaskForPool<T> implements Runnable {
    private final MyObjectPool<T> pool;
    private final CountDownLatch latch;
    private static final Logger logger = Logger.getLogger(TaskForPool.class.getName());
	public TaskForPool (MyObjectPool<T> pool, CountDownLatch latch) {
		this.pool = pool;
		this.latch = latch;
	}
	public void run() {
		try {
			T object = pool.checkOut();
			logger.info("Checkout "+Thread.currentThread().getName());
            Thread.sleep(200);
			pool.checkIn(object);
			logger.info("Checkin "+Thread.currentThread().getName());
			latch.countDown();
		} catch (InterruptedException e) {
			Thread.currentThread().interrupt();
			e.printStackTrace();
		}
    }
}